#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>

static void sig_handler(int sig){
    printf("Get Sign!\n");
}

int main(void)
{
    struct sigaction sig = {0};
    sigset_t wait_mask;

    sigemptyset(&wait_mask);

    sig.sa_handler = sig_handler;
    sig.sa_flags = 0;
    if(-1 == sigaction(SIGUSR1, &sig, NULL)){
        perror("sigaction error");
        exit(-1);
    }

    switch(fork()){
        case -1:
            perror("fork error");
            exit(-1);

        case 0:
            printf("child fork start\n");
            printf("child print\n");
            printf("~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            sleep(2);
            kill(getppid(), SIGUSR1);
            _exit(0);

        default:
            if(-1 != sigsuspend(&wait_mask))
                exit(-1);

            printf("parent fork start\n");
            printf("parent fork printf\n");
            printf("~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            exit(0);
    }
}